/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package controller.database;

import java.util.List;
import javax.ejb.Stateless;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.primefaces.event.CellEditEvent;

/**
 *
 * @author Shengyi_Chen
 */
@Stateless
@Named

public class CheckpointFacade extends AbstractFacade<Checkpoint> {
    @PersistenceContext(unitName = "va-big-sitePU")
    private EntityManager em;
    
    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CheckpointFacade() {
        super(Checkpoint.class);
    }

    public List<Checkpoint> getCheckpoint() {
        return em.createNamedQuery("Checkpoint.findAll").getResultList();
    }
    
    public void onEdit(CellEditEvent event) {
        Object oldValue = event.getOldValue();  
        Object newValue = event.getNewValue();
        
        FacesMessage msg = new FacesMessage("Event Edited", "from old: " + oldValue.toString() + " to: " + newValue.toString() );
        
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }
}
